package com.zzx.magic.service.impl;

import com.alibaba.fastjson.JSON;
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
import com.zzx.magic.entity.NotifyDto;
import com.zzx.magic.service.NativePayService;

import java.security.GeneralSecurityException;
import java.util.Map;

/**
 * @Author Zhangxx
 * @Date 2024/6/20 16:56
 */
public class NativePayServiceImpl implements NativePayService {
    private String apiV3Key ="CZBK51236435wxpay435434323FFDuv3";

    @Override
    public void notify(NotifyDto dto) {


        String jsonStr = null;
        try {
            jsonStr = new AesUtil(apiV3Key.getBytes())
                    .decryptToString(dto.getResource().getAssociated_data().getBytes(),
                            dto.getResource().getNonce().getBytes(),
                            dto.getResource().getCiphertext());
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
        }


        Map map = JSON.parseObject(jsonStr, Map.class);
        String outTradeNo = map.get("out_trade_no").toString();

        System.out.println("订单"+outTradeNo+"支付成功");
    }
}